package flc.ast.fragment;

import android.Manifest;
import android.os.Bundle;

import androidx.databinding.ViewDataBinding;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.R;
import flc.ast.activity.CalculateActivity;
import flc.ast.activity.FileTransferActivity;
import flc.ast.activity.MapNavActivity;
import flc.ast.activity.MetronomeActivity;
import flc.ast.activity.PlantRecActivity;
import flc.ast.activity.TextRecActivity;
import flc.ast.activity.TranslateActivity;
import flc.ast.databinding.FragmentToolBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.StkPermissionHelper;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link ToolFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class ToolFragment extends BaseNoModelFragment<FragmentToolBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_tool;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);
        mDataBinding.rlCalculate.setOnClickListener(this);
        mDataBinding.rlPlantRec.setOnClickListener(this);
        mDataBinding.rlTranslate.setOnClickListener(this);
        mDataBinding.ivMetronome.setOnClickListener(this);
        mDataBinding.ivMapNav.setOnClickListener(this);
        mDataBinding.ivFileTransfer.setOnClickListener(this);
        mDataBinding.ivTextRec.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.rlCalculate://计算器
                startActivity(CalculateActivity.class);
                break;
            case R.id.rlPlantRec://植物识别
                startActivity(PlantRecActivity.class);
                break;
            case R.id.rlTranslate://翻译器
                startActivity(TranslateActivity.class);
                break;
            case R.id.ivMetronome://节拍器
                startActivity(MetronomeActivity.class);
                break;
            case R.id.ivMapNav://地图导航
                StkPermissionHelper.permission(Manifest.permission.ACCESS_FINE_LOCATION)
                        .reqPermissionDesc(getString(R.string.get_location_permission))
                        .callback(new StkPermissionHelper.ACallback() {
                            @Override
                            public void onGranted() {
                                startActivity(MapNavActivity.class);
                            }
                        }).request();
                break;
            case R.id.ivFileTransfer://文件传送
                getTransferPermission();
                break;
            case R.id.ivTextRec://图文识别
                startActivity(TextRecActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void getTransferPermission() {
        StkPermissionHelper.permission(StkPermissionHelper.Permission.ACCESS_IMAGE_VIDEO, Manifest.permission.CAMERA, Manifest.permission.READ_CONTACTS,Manifest.permission.WRITE_CONTACTS)
                .reqPermissionDesc(getString(R.string.get_transfer_permission))
                .callback(new StkPermissionHelper.ACallback() {
                    @Override
                    public void onGranted() {
                        startActivity(FileTransferActivity.class);
                    }

                    @Override
                    public void onDenied(boolean needGoSettings) {
                        ToastUtils.showShort(getString(R.string.no_permission));
                    }
                }).request();
    }

}